/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
 * Description: 
 * Author: g00421808
 * Create: 6/30/2022
 * Notes: 
 */

#ifndef JSBIND_METHOD_BINDER_H
#define JSBIND_METHOD_BINDER_H
#include "binder.h"

namespace Jsb {

/**
 * @brief: 类成员函数类型Binder，定义所有类成员函数回调类型为：R (C::*)(P...)的回调Binder
 */
template <typename BinderType, typename C, typename M, typename R, typename... P>
class MethodBinder : public TemplatedBinder<BinderType, M, R, P...> {
public:

    // | static |
    /**
     * @brief: 根据ClassType::Method注册时的Invoker Id获取调用器对象进行函数实体调用
     * @param: receiver: 类实例对象
     *         binderInfo: invoker索引ID
     *         args: 扩展参数包
     * @Note: 注意入参必须是引用，如果传值前是指针，需要解指针
     */
    template<typename... Args>
    static R InnerWrapper(C& receiver, Jsb::BindInfo* bindInfo, Args&&... args) {
        const auto& invokerInfo = BinderType::GetInvoker(bindInfo->methodNumber);
        return Invoker<R (*)(P...)>::InvokeMethod(receiver, invokerInfo.invoker, std::forward<Args>(args)...);
    }

    static constexpr auto type = Binder::Type::Method;

};
} // namespace Jsb
#endif //JSBIND_METHOD_BINDER_H
